#version 300 es

#ifdef GL_ES
precision mediump float;
#endif

#define TWO_PI 6.28318530718

uniform vec2 u_resolution;
uniform float u_time;
float minStep = 0.01;

out vec4 outColor;

void main() {

  float solution = min(u_resolution.x, u_resolution.y);
  minStep = 1.0 / solution;
  vec2 st = (gl_FragCoord.xy - u_resolution / 2.0) * minStep;
  vec2 s = vec2(1.0, 1.0) - step(0.5, abs(st));
  if(s.x * s.y < 0.00001) {
    discard;
  }

  vec3 color = vec3(0.075, 0.413, 0.750);
  float d = 0.0;

  // Remap the space to -1. to 1.
  st *= 2.0;

  // Make the distance field
  d = length(abs(st) - 0.3);
  // d = length(min(abs(st) - 0.3, 0.0));
  // d = length(max(abs(st) - 0.3, 0.0));

  // Visualize the distance field
  d = fract(d * 10.0);
  outColor = vec4(vec3((1.0 - smoothstep(1.0 - minStep * 30.0, 1.0, d)) * d), 1.0);

  // Drawing with the distance field
  // outColor = vec4(vec3(step(0.3, d)), 1.0);
  // outColor = vec4(vec3(step(0.3, d) * step(d, .4)), 1.0);
  // outColor = vec4(vec3(smoothstep(0.3, 0.4, d) * smoothstep(0.6, 0.5, d)), 1.0);
}